<template>
  <div class="make-skills">
    <div class="header">
      <el-button @click="handleAdjust()">{{
        chapterList && chapterList.length > 0 ? "调整维度" : "添加维度"
      }}</el-button>
    </div>

    <!-- 技能维度列表 -->
    <div class="skills-list" v-if="chapterList && chapterList.length > 0">
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-collapse-item
          :title="item.name"
          :name="item.name"
          v-for="item in chapterList"
          :key="item.id"
        >
          <div v-for="skill in item.chapterList" :key="skill.id">
            {{ skill.name }}
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
    <div class="no-chapter" v-else>
      <img src="@/assets/img/no-data.png" alt="" />
      <span>暂无内容</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      courseId: "",
      activeNames: [],
      chapterList: [],
    };
  },
  created() {
    this.courseId = JSON.parse(localStorage.getItem("courseId"));
    this.getSkillsList();
  },
  methods: {
    getSkillsList() {
      this.$axios
        .get(`/tes/course/${this.courseId}/chapter-course-sort-list`)
        .then((res) => {
          this.chapterList = res.data || [];
          // 默认展开所有折叠面板
          this.activeNames = this.chapterList.map((item) => item.name);
        });
    },
    handleChange(val) {
      console.log(val);
    },
    handleAdjust() {
      this.$router.push({
        path: "/aiTeaching/courseBuild/makeSkillsTrim",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.make-skills {
  background-color: #fff;
  padding: 40px 60px;
  box-sizing: border-box;
  min-height: 650px;
  .header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .el-button {
      margin-left: 0;
      background: #457aff;
      border-radius: 4px;
      color: #fff;
    }
  }
  .skills-list {
    margin-top: 22px;
    :deep(.el-collapse) {
      .el-collapse-item__header.is-active {
        background-color: #f0f4fd;
      }
      .el-collapse-item__header {
        padding-left: 30px;
        background-color: #fafafa;
        font-weight: bold;
        font-size: 16px;
        color: #7a8cb0;
      }
      .el-collapse-item__content {
        padding: 20px 0 20px 50px;
        font-weight: 400;
        font-size: 16px;
        color: #6b6a85;
      }
    }
  }
  .no-chapter {
    padding: 150px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    img {
      width: 237px;
      height: 90px;
    }
    span {
      font-size: 14px;
      color: #999;
    }
  }
}
</style>